package com.tinygone.user.controller;

import com.tinygone.user.feign.IMovieFeignClient;
import com.tinygone.user.pojo.Movie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class UserController {
    @Autowired
    private RestTemplate restTemplate;

    @Value("${user.movieUrl}")
    private String movieUrl;

    @GetMapping("/movies/{id}")
    public Movie getMovieById(@PathVariable String id) {
        Movie movie = restTemplate.getForObject(movieUrl + "movie/" + id, Movie.class);
        return movie;
    }

    @Autowired
    IMovieFeignClient movieFeignClient;

    @GetMapping("/feign-test1")
    public String feignTest1() {
        return movieFeignClient.test1();
    }

    @GetMapping("/feign-test2/{id}")
    public Movie feignTest2(@PathVariable(name = "id") String id) {
        return movieFeignClient.getMovieById(id);
    }

    @PostMapping(value = "feign-test3")
    public Movie moviePost(Movie movie) {
        return movieFeignClient.postMovie(movie);
    }


}
